Below is a function that replaces the hostname in a URL in C#. I take 2 arguments, the old and new host then returns the new host that can be pinged and browsed:
public static string ReplaceHost(string originalHost, string newHost) { UriBuilder _builder = new UriBuilder(originalHost); _builder.Host = new Uri(newHost).Host; return _builder.ToString(); }
Now call the function from the main method:
static void Main(string[] args) { string NewHost = ReplaceHost("http://tutorialspanel.com", "http://www.tutorialspanel.com"); Console.WriteLine(NewHost); Console.ReadKey(); }
Output
http://www.tutorialspanel.com:80/
Check for Even or Odd Number Using C#
Comments